package cn.eyesea.cc.frame.component;

import cn.eyesea.cc.entity.DomainInfo;
import cn.eyesea.cc.frame.base.ResultResource;
import cn.eyesea.cc.frame.base.impl.resultresource.VariableResultResource;
import cn.eyesea.cc.frame.enums.LogicalResultTypeEnum;
import cn.eyesea.cc.frame.enums.LogicalTypeEnum;
import cn.eyesea.cc.frame.enums.ResultTypeEnum;
import cn.eyesea.cc.util.NameUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 名字组件
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/7/29 7:57 下午
 */
@Slf4j
public class NameComponent {


    public static String createResultResourceName(DomainInfo domainInfo, LogicalTypeEnum logicalTypeEnum) {
        LogicalResultTypeEnum logicalResultType = logicalTypeEnum.getLogicalResultType();
        ResultTypeEnum resultType = logicalResultType.getResultType();
        String name = domainInfo.getTable() + "_" + logicalResultType.getSuffix();
        switch (resultType) {
            case XML:
            case JAVA_CLASS:
            case JAVA_INTERFACE:
                return NameUtils.getInstance().getClassName(name);
            default:
                log.info("domainInfo:{} logicalTypeEnum:{}", domainInfo, logicalResultType);
                throw new RuntimeException("not find match resultType");
        }
    }

    public static String getFullName(ResultResource resultResource) {
        return resultResource.getPackageInfo() + "." + resultResource.getName();
    }
}
